home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT34.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.3 KB  |  133 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 34                         
  5.                                                                               
  6.   This program shows how WGT for Watcom can create absolutley HUGE blocks.    
  7.   It also demonstrates how to use wsetscreen to direct output to ANY block    
  8.   regardless of dimensions. An image is created by allocating a large         
  9.   block from whatever memory is available and then randomly scattering        
  10.   200 "smaller" 64k images throughout the larger block.                       
  11.                                                                               
  12.   Once this is done, click and move the mouse to scroll the large block.      
  13.                                                                               
  14.   *** PROJECT ***                                                             
  15.   This program requires the file WGT5_WC.LIB to be linked.                    
  16.                                                                               
  17.   *** DATA FILES ***                                                          
  18.   WGT1.PCX must be in your executable directory.                 
  19.                                                            WATCOM C++ VERSION 
  20. ==============================================================================
  21. */
  22.  
  23. #include <math.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <wgt5.h>
  27.  
  28. block pic, bigpic;
  29. color pal[256];
  30.  
  31. void main (void)
  32. {
  33.   int freeram;
  34.   int dimension;
  35.   short oldmode;
  36.   short ctr;
  37.   short ox, oy, sx, sy, vx, vy;
  38.  
  39.   printf ("WGT Example #34\n\n");
  40.   printf ("A LARGE virtual screen is created using as much free ram as possible,\n");
  41.   printf ("and then it may be viewed by clicking and dragging the mouse cursor to set a\n");
  42.   printf ("new viewing location. Press a key to end the program at any time.\n");
  43.   printf ("\n\nPress any key to continue.\n");
  44.   getch ();
  45.  
  46.   oldmode = wgetmode ();
  47.  
  48.   pic = wloadpcx ("wgt1.pcx", pal);
  49.   
  50.  
  51.   /* Find free ram and create a block using almost all memory available */
  52.   freeram = getmemfree ();
  53.   printf ("Free memory %d\n", freeram);
  54.   dimension = sqrt (freeram - 100000);  
  55.   printf ("Block dimensions %d by %d\n", dimension, dimension);  
  56.   printf ("\n\n\nPress a key.\n");
  57.   getch ();
  58.   
  59.   vga256 ();
  60.   wsetpalette (0, 255, pal);
  61.  
  62.   bigpic = wallocblock (dimension, dimension);
  63.   
  64.   wtextcolor (200);
  65.   wtexttransparent (TEXTFG);
  66.   wouttextxy (0, 80, NULL, "HUGE block allocated");
  67.   wouttextxy (0, 100, NULL, "Now shuffling blocks.....");
  68.   
  69.   /* Set all output to our huge block, then randomly paste 200 small blocks */
  70.   wsetscreen (bigpic);
  71.   for (ctr = 0; ctr < 200; ctr++)
  72.     wputblock (rand () % dimension, rand () % dimension, pic, NORMAL);
  73.  
  74.   /* Return to normal viewing screen and allow user to view big block */
  75.   wnormscreen ();
  76.   wputblock (0, 0, bigpic, NORMAL);
  77.   vx = 0;
  78.   vy = 0;
  79.   wouttextxy (0, 0, NULL, "Viewing (0, 0)");
  80.   minit ();
  81.   mon ();
  82.   wtexttransparent (TEXTFGBG);
  83.   while (!kbhit ())
  84.   {
  85.     if (mouse.but > 0)
  86.     {
  87.       sx = mouse.mx; 
  88.       sy = mouse.my;
  89.       ox = vx;
  90.       oy = vy;
  91.       moff ();
  92.       while (mouse.but > 0)
  93.       {
  94.         if ((mouse.mx != sx) || (mouse.my != sy))
  95.         {
  96.           /* Shift image base on mouse coordinates */
  97.           ox = vx - (sx - mouse.mx);
  98.           oy = vy - (sy - mouse.my);
  99.  
  100.           /* Now check to make sure we didn't go past end of image */
  101.           if (ox + dimension < 320)
  102.             ox = 320 - dimension;
  103.           if (oy + dimension < 200)
  104.             oy = 200 - dimension;
  105.           if (ox > 0)
  106.             ox = 0;
  107.           if (oy > 0)
  108.             oy = 0;
  109.  
  110.           /* Now show the image*/
  111.           wputblock (ox, oy, bigpic, NORMAL);
  112.           
  113.           /* TRY DELETING THE FOLLOWING TWO LINES AND RUNNING THE PROGRAM */
  114.           sx = mouse.mx;
  115.           sy = mouse.my;
  116.  
  117.           vx = ox;
  118.           vy = oy;
  119.           wgtprintf (0, 0, NULL, "Viewing (%d, %d)", -vx, -vy);
  120.         }
  121.       }
  122.       mon ();
  123.     }
  124.   }
  125.   getch ();
  126.   moff ();
  127.   mdeinit ();
  128.   wfreeblock (bigpic);
  129.   wfreeblock (pic);
  130.   wsetmode (oldmode);
  131. }
  132.  
  133.